﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace Fractalz.FileIO
{
	/// <summary>
	/// Functionality for saving fractals and opening fractals from files.
	/// </summary>
	class XMLFileIO
	{
		/// <summary>
		/// Writes a fractal's parameters to a save file.
		/// </summary>
		/// <param name="filename">The name of the save file.</param>
		/// <param name="fractalParams">The parameters to be saved.</param>
		public void writeFile(String filename, MainWindow.FractalParameters fractalParams)
		{
			XmlTextWriter writer = new XmlTextWriter(filename, null);
			
			// Use automatic indenting for readability
			writer.Formatting = Formatting.Indented;

			writer.WriteStartElement("fractal");

			writer.WriteAttributeString("type", fractalParams.type.ToString());

			writer.WriteAttributeString("midpointX", fractalParams.midpointX.ToString());

			writer.WriteAttributeString("midpointY", fractalParams.midpointY.ToString());

			writer.WriteAttributeString("distanceX", fractalParams.distanceX.ToString());

			writer.WriteAttributeString("distanceY", fractalParams.distanceY.ToString());

			writer.WriteAttributeString("resolution", fractalParams.resolution.ToString());

			writer.WriteAttributeString("antiAliasingLevel", fractalParams.antiAliasLevel.ToString());

			// That's all the shit for now...

			writer.WriteEndElement();

			writer.Close();
		}

	}
}
